Discord Hono
luisfun/discord-hono: This module enables you to easily build a Discord Bot that runs on Cloudflare workers
Discord Hono | Discord Hono
Serverless bot
無法建立持續連線
例如連至語音通話、持續監看留言或反應
主要以Discord Interactions和REST API進行處理
基本上遵循Hono的設計概念,透過c物件處理請求和回應
wrangler.toml為使用Cloudflare Workers時的相關設定用檔案
.env儲存相關敏感資訊
使用npx wrangler推送識別資訊至雲端
$ npx wrangler secret put DISCORD_APPLICATION_ID
$ npx wrangler secret put DISCORD_PUBLIC_KEY
$ npx wrangler secret put DISCORD_TOKEN
取得使用者名稱
Discord Developer Portal — Documentation — Receiving and Responding
${c.interaction.member.user.username}
<@${c.interaction.member.user.id}>
定時排程
cron
傳送DM
Users Resource | Documentation | Discord Developer Portal
本地執行
Hosting a Reddit API Discord app on Cloudflare Workers | Documentation | Discord Developer Portal
嵌入多張圖片
Embed with multiple Images - discord.js - Imagine an app
想顯示為格狀時,需將每個嵌入的url設為相同的值
code:javascript
embeds: [
new Embed().url('some url here').image({ url: 'image url 1' }),
new Embed().url('some url here').image({ url: 'image url 2' }),
new Embed().url('some url here').image({ url: 'image url 3' }),
]
如果單純嵌入,會變為一連長串
code:javascript
embeds: [
new Embed().image({ url: 'image url 1' }),
new Embed().image({ url: 'image url 2' }),
new Embed().image({ url: 'image url 3' }),
]
嵌入
Using Embeds in messages
Embed Generator | Discord embeds without the hassle
搭配Hono使用
Tips | Discord Hono
hono.mount('/interaction', discord.fetch)
使用定時排程
code:javascript
export default {
fetch: app.fetch,
scheduled: bot.scheduled
}